//
//  HomePageViewController.m
//  SweetComics
//
//  Created by LeeZhe on 15/1/28.
//  Copyright (c) 2015年 LeeZhe. All rights reserved.
//

#define kURLOne @"http://mobilev3.ac.qq.com/Classify/comicCategoryListForIos/category_id/15/page/1/listcnt/12/clientType/0/local_version/1"


#import "FirstView.h"
#import "TotalCell.h"
#import "AFHTTPRequestOperationManager.h"
#import "SecondCell.h"
#import "DetailViewController.h"
#import "ThirdCell.h"
#import "TopicCell.h"
#import "GirlCell.h"
#import "TopicTwoCell.h"
#import "ComicsListViewController.h"
#import "NewComicsListViewController.h"
#import "TopicListViewController.h"// 专题列表
#import "AppDelegate.h"
#import "ClassifyViewController.h"
#import "RootViewController.h"
#import "SearchViewController.h"
#import "NewComicsListViewController.h"
#import "Reachability.h"

@interface HomePageViewController ()<UITableViewDelegate,UITableViewDataSource,firstViewDelegate,UIAlertViewDelegate,UIActionSheetDelegate>
@property (nonatomic,retain)NSMutableArray *arr;
@property (nonatomic,retain)UITableView *tableView;
@property (nonatomic,retain)ComicList *comics;
@property (nonatomic,retain)ComicList *comicsThird; // 少年
@property (nonatomic,retain)ComicList *comicsForth; //专题1 model 类传值
@property (nonatomic,retain)ComicList *comicsFive; // 少女 model 类传值
@property (nonatomic,retain)ComicList *comicsSix; //专题2 model 类传值
@property (nonatomic,retain)NSMutableArray *arrTwo; // 存纯情漫画对象
@property (nonatomic,retain)NSMutableArray *arrThree; // 放纯情漫画
@property (nonatomic,retain)NSMutableArray *arrFour; //放热门漫画
@property (nonatomic,retain)NSMutableArray *juniorArr; // 少年对象
@property (nonatomic,retain)NSMutableArray *girlArr; // 少女对象.
@property (nonatomic,retain)NSMutableArray *topicTwoArr; // 存放专题2 数组.
@property (nonatomic,retain)NSNotificationCenter *notify;
@property (nonatomic,retain)MBProgressHUD *mbView;

@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.
    navigationController.navigationBar.barTintColor = [UIColor orangeColor];

    
    if ([self reachAbility]) {
        
        
        [self createView];
        [self  NetWorlOne];
        
        
        
    }else
    {

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
        imageView.image = [UIImage imageNamed:@"replace.png"];
        [self.view addSubview:imageView];
        [imageView release];
    }
    
    self.title = @"首页";
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(action:) name:@"zhao" object:nil];
    NSNotificationCenter *centerThird = [NSNotificationCenter defaultCenter];
    [centerThird addObserver:self selector:@selector(actionThird:) name:@"third" object:nil];
    NSNotificationCenter *centerFour = [NSNotificationCenter defaultCenter];
    [centerFour addObserver:self selector:@selector(actionFour:) name:@"topic" object:nil];
    NSNotificationCenter *centerGirl = [NSNotificationCenter defaultCenter];
    [centerGirl addObserver:self selector:@selector(actionFive:) name:@"girl" object:nil];
    NSNotificationCenter *centerFive = [NSNotificationCenter defaultCenter];
    [centerFive addObserver:self selector:@selector(actionSix:) name:@"topicTwo" object:nil];
    //    NSLog(@"%f",self.view.frame.size.width);
    
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-dibudaohangfenlei2.png"] style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)] autorelease];
    //    ShowImageCell *show = [[ShowImageCell alloc] init];
    //    show.delegate = self;
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(barButtonAction1:)]autorelease];
}
- (void)MBView
{
    
    self.mbView = [[MBProgressHUD alloc] initWithView:self.view];
    [_mbView show:YES];
    //    [_mbView hide:YES afterDelay:4];
    _mbView.labelText = @"努力加载中";
    _mbView.labelFont = [UIFont systemFontOfSize:12];
    [self.view addSubview:_mbView];
    
}
// 热门漫画
- (void)action:(NSNotification *)notify
{
    self.comics = [[ComicList alloc] init];
    self.comics = notify.object;
    NSLog(@"热门  %@",self.comics.comic_list_title);
    
}
// 第三个MVC 传值的方法 少年
- (void)actionThird:(NSNotification *)notify
{
    self.comicsThird = [[ComicList alloc] init];
    self.comicsThird = notify.object;
    //    NSLog(@"%@",_comicsThird.comic_list_title);
}

// 第四个MVC 传值  话题;
- (void)actionFour:(NSNotification *)notify
{
    self.comicsForth = [[ComicList alloc] init];
    self.comicsForth = notify.object;
    NSLog(@" com %ld",(unsigned long)_comicsForth.data.count);
    //    NSLog(@"notify %@",notify);
}
// MVC 传值 少女
- (void)actionFive:(NSNotification *)notify
{
    self.comicsFive = [[ComicList alloc] init];
    self.comicsFive = notify.object;
    
}
// MVC 传值 专题2
- (void)actionSix:(NSNotification *)notify
{
    self.comicsSix = [[ComicList alloc] init];
    self.comicsSix = notify.object;
    
}
// 实现代理方法  想 collection 推送到详情页面


- (void)pushToDetailControll:(NSMutableArray *)array
{
    NewComicsListViewController *newVC = [[[NewComicsListViewController alloc] init] autorelease];
    newVC.comicId = @"6";
    newVC.title = @"Sweet";
    [self.navigationController pushViewController:newVC animated:YES];
    
}



- (void)createView
{
    //    NSLog(@"%g",self.view.frame.size.height);
    self.navigationController.navigationBar.translucent = NO;

    
    FirstView *first = [[FirstView alloc] initWithFrame:CGRectMake(0,50, self.view.frame.size.width,0.45 * self.view.frame.size.height)];
    [first createView];
    first.delegate = self;
    first.backgroundColor = [UIColor redColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableHeaderView = first;
    
    //    [first addObserver:self forKeyPath:@"arr" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld  context:@"随便"];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"漫画列表" forState: UIControlStateNormal];
    [button addTarget:self action:@selector(buttonComicsList:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:17];
    button.frame = CGRectMake(first.frame.size.width * 0.733, 15,self.view.frame.size.width * 0.267,40);
    [first addSubview:button];
    
    
    _tableView.separatorStyle  = UITableViewCellSeparatorStyleSingleLineEtched;
    UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:self.tableView.bounds];
    //    backgroundView.image = [UIImage imageNamed:@"HappyLife.jpg"];
    self.tableView.backgroundColor = [UIColor whiteColor];
    [backgroundView release];
    [self.view addSubview:_tableView];
    [_tableView release];
    
}

// 观察者实现方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    //    if (keyPath != nil) {
    //        [_mbView removeFromSuperview];
    //    }
}
// 跳转到ComicsListViewControllerr漫画列表页面
- (void)buttonComicsList:(UIButton *)button
{
    NewComicsListViewController *c = [[NewComicsListViewController alloc] init];
    c.comicId = @"19";
    c.title = @"甜心漫画";
    [self.navigationController pushViewController:c animated:YES];
    [c release];
}

- (BOOL)reachAbility
{
    Reachability *r = [Reachability reachabilityForInternetConnection];
    if (r.currentReachabilityStatus ==  0) {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"网络提示" delegate:self cancelButtonTitle:@"联网重新加载" destructiveButtonTitle:@"没有网路哦" otherButtonTitles:nil];
        [actionSheet showInView:self.view];
        [actionSheet release];
        return NO;
    }
    return YES;
    
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    [self createView];
    [self NetWorlOne];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self createView];
    [self NetWorlOne];
//    self.navigationController.navigationBar.translucent = YES;

    
}

- (void)NetWorlOne
{
    [self MBView];
    
    self.arrTwo = [NSMutableArray array];
    self.arrThree = [NSMutableArray array];
    self.arrFour = [NSMutableArray array];
    self.juniorArr = [NSMutableArray array];
    self.girlArr = [NSMutableArray array];
    self.topicTwoArr = [NSMutableArray array];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = [kURLOne stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSMutableDictionary *dic = responseObject;
        ComicList *comics = [[ComicList alloc] init];
        [comics setValuesForKeysWithDictionary:dic];
        [self.arrTwo addObject:comics];
        [self.tableView reloadData];
        [_mbView hide:YES];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
        // 如果网络请求失败/ 没有网络,则移除视图 加载没有网络的视图.
        //        [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        imageView.image = [UIImage imageNamed:@"replace.png"];
        [self.view addSubview:imageView];
        [imageView release];
        [self MBView];
        [_mbView hide:YES afterDelay:4];
        
        [NSThread sleepForTimeInterval:3];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"网络连接失败拉\r甜心偷懒了哦" delegate: self cancelButtonTitle:@"联网重试" otherButtonTitles:nil];
        [alertView show];
        [self.view addSubview:alertView];
        [alertView release];
    }];
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 5) {
        return 170;
    }
    
    return 200;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *a = @"第一个";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:a];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:a];
    }
    
    
    if (indexPath.row == 0) {
        ComicList *comics = [self.arrTwo firstObject];
        static NSString *shaonian = @"少年";
        TotalCell *totalCell = [self.tableView dequeueReusableCellWithIdentifier:shaonian];
        if (!totalCell) {
            totalCell = [[[TotalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:shaonian] autorelease];
        }
        [totalCell setComics:comics];
        for (NSInteger i = 0; i < comics.data.count; i++) {
            
            totalCell.button = [UIButton buttonWithType:UIButtonTypeSystem];
            totalCell.button.frame = CGRectMake(120 * i,0,110,145);
            totalCell.button.tag = i + 1;
            //            [totalCell.button setTitle:nil forState:UIControlStateNormal];
            [totalCell.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            [totalCell.scrollView addSubview:totalCell.button];
        }
        [totalCell.totalButton addTarget:self action:@selector(totalButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        return totalCell;
    }
    
    
    
    
    
    
    
    else if (indexPath.row == 1) // 热门漫画
    {
        
        
        ComicList *comics = [[ComicList alloc] init];
        
        static NSString *s = @"123";
        SecondCell *totalCell = [self.tableView dequeueReusableCellWithIdentifier:s];
        if (!totalCell) {
            totalCell = [[[SecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:s ] autorelease];
        }
        [totalCell setComics:comics];
        [totalCell.totalButton addTarget:self action:@selector(hotListButton:) forControlEvents:UIControlEventTouchUpInside];
        for (NSInteger i = 0; i < 12 ;i++) {
            
            totalCell.button = [UIButton buttonWithType:UIButtonTypeSystem];
            totalCell.button.frame = CGRectMake(120 * i,0,110,145);
            totalCell.button.tag = i + 1;
            [totalCell.button setTitle:nil forState:UIControlStateNormal];
            [totalCell.button addTarget:self action:@selector(buttonActionTwo:) forControlEvents:UIControlEventTouchUpInside];
            [totalCell.scrollView addSubview:totalCell.button];
            
        }
        return totalCell;
    }else if (indexPath.row == 2) // 专题 topic
    {
        ComicList *comics = [[ComicList alloc] init];
        
        static NSString *two = @"two";
        TopicCell *topicCell = [self.tableView dequeueReusableCellWithIdentifier:two];
        if (!topicCell) {
            topicCell = [[[TopicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:two] autorelease];
            
        }
        [topicCell setComics:comics];
        for (NSInteger i = 0; i < 4; i++) {
            
            topicCell.button = [UIButton buttonWithType:UIButtonTypeSystem];
            topicCell.button.frame = CGRectMake(i % 2 * (0.493 * self.view.frame.size.width),i / 2 * 100 + 10,0.467 * self.view.frame.size.width,90);
            topicCell.button.tag = i + 1;
            
            //            [topicCell.button setTitle:@"点击" forState:UIControlStateNormal];
            
            [topicCell.button addTarget:self action:@selector(buttonActionFour:) forControlEvents:UIControlEventTouchUpInside];
            //            topicCell.button.backgroundColor = [UIColor redColor];
            [topicCell.contentView addSubview:topicCell.button];
            //            NSLog(@"专题 %@",_comicsForth.data);
        }
        
        return topicCell;
        
        
    }
    
    
    
    
    // 少年
    else if (indexPath.row == 3)
    {
        ComicList *comics = [[ComicList alloc] init];
        
        static NSString *third = @"3";
        ThirdCell *totalCell = [self.tableView dequeueReusableCellWithIdentifier:third];
        if (!totalCell) {
            totalCell = [[ThirdCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:third];
        }
        [totalCell setComics:comics];
        for (NSInteger i = 0; i < 12 ;i++) {
            
            totalCell.button = [UIButton buttonWithType:UIButtonTypeSystem];
            totalCell.button.frame = CGRectMake(120 * i,0,110,145);
            totalCell.button.tag = i + 1;
            [totalCell.button setTitle:nil forState:UIControlStateNormal];
            [totalCell.button addTarget:self action:@selector(buttonActionThree:) forControlEvents:UIControlEventTouchUpInside];
            [totalCell.scrollView addSubview:totalCell.button];
            
        }
        [totalCell.totalButton addTarget:self action:@selector(juniorButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        return totalCell;
    }
    // 少女 Cell
    else if (indexPath.row == 4) {
        ComicList *comics = [[ComicList alloc] init];
        
        static NSString *girl = @"girl";
        GirlCell *totalCell = [self.tableView dequeueReusableCellWithIdentifier:girl];
        if (!totalCell) {
            totalCell = [[[GirlCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:girl] autorelease];
        }
        [totalCell setComics:comics];
        [totalCell.totalButton addTarget:self action:@selector(girlButtonListAction:) forControlEvents:UIControlEventTouchUpInside];
        for (NSInteger i = 0; i < 12 ;i++) {
            
            totalCell.button = [UIButton buttonWithType:UIButtonTypeSystem];
            totalCell.button.frame = CGRectMake(120 * i,0,110,145);
            totalCell.button.tag = i + 1;
            [totalCell.button setTitle:nil forState:UIControlStateNormal];
            [totalCell.button addTarget:self action:@selector(buttonActionFive:) forControlEvents:UIControlEventTouchUpInside];
            [totalCell.scrollView addSubview:totalCell.button];
            
        }
        return totalCell;
    }
    else if (indexPath.row == 5) // 专题 topic
    {
        ComicList *comics = [[ComicList alloc] init];
        
        static NSString *topicTwo = @"topicTwo";
        TopicTwoCell *topicCell = [self.tableView dequeueReusableCellWithIdentifier:topicTwo];
        if (!topicCell) {
            topicCell = [[[TopicTwoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:topicTwo] autorelease];
            
        }
        [topicCell setComics:comics];
        for (NSInteger i = 0; i < 5; i++) {
            
            topicCell.button = [UIButton buttonWithType:UIButtonTypeSystem];
            topicCell.button.frame = CGRectMake(i % 2 * (0.493 * self.view.frame.size.width),i / 2 * 100 + 10,0.467 * self.view.frame.size.width,90);;
            topicCell.button.tag = i + 1;
            
            
            [topicCell.button addTarget:self action:@selector(buttonActionSix:) forControlEvents:UIControlEventTouchUpInside];
            //              topicCell.button.backgroundColor = [UIColor redColor];
            [topicCell.contentView addSubview:topicCell.button];
            //                          NSLog(@"专题 %@",_comics.data);
        }
        
        return topicCell;
        
        
    }
    
    
    
    return cell;
    
    
    
    
}
// 纯情漫画跳转漫画详情页面 DetailViewController
- (void)buttonAction:(UIButton *)button
{
    ComicList *comics  = [self.arrTwo firstObject];
    for (NSDictionary *dic in comics.data) {
        ComicList *comicsTwo = [[ComicList alloc] init];
        [comicsTwo setValuesForKeysWithDictionary:dic];
        [self.arrThree addObject:comicsTwo];
    }
    for (NSInteger i = 0; i < comics.data.count; i++) {
        if (button.tag == i + 1) {
            //            NSLog(@"%@33333",[[comics.data objectAtIndex:i] objectForKey:@"title"]);
            DetailViewController *detail = [[DetailViewController alloc] init];
            detail.comic = [self.arrThree objectAtIndex:i];
            
            [self.navigationController pushViewController:detail animated:YES];
            [detail release];
        }
        
    }
}
// 热门漫画 -> 漫画详情页面 DetailViewController
- (void)buttonActionTwo:(UIButton *)button
{
    for (NSDictionary *dic in self.comics.data) {
        ComicList *comic = [[ComicList alloc] init];
        [comic setValuesForKeysWithDictionary:dic];
        [self.arrFour addObject:comic];
        [comic release];
    }
    
    //    NSLog(@"%@",_comicsThird.comic_list_title);
    
    for (NSInteger i = 0; i < _comics.data.count; i++) {
        if (button.tag == i + 1) {
            DetailViewController *detail = [[DetailViewController alloc] init];
            [self.navigationController pushViewController:detail animated:YES];
            detail.comic = [self.arrFour objectAtIndex:i];
            [detail release];
        }
        
    }
    
    
}

//跳转至少年漫画列表页面
- (void)juniorButtonAction:(UIButton *)button
{
    //    NSLog(@"%@",_comicsThird.data);
    ComicsListViewController *comicsVC = [[ComicsListViewController alloc] init];
    [self.navigationController pushViewController:comicsVC animated:YES];
    comicsVC.comic_list_id = self.comicsThird.comic_list_id;
    //    NSLog(@"%@ 111",self.comicsThird.comic_list_id);
    comicsVC.title = self.comicsThird.comic_list_title;
    [comicsVC release];
    
}



// 跳转至少年漫画详情页面.
- (void)buttonActionThree:(UIButton *)button
{
    for (NSMutableDictionary *dic in self.comicsThird.data) {
        ComicList *comic = [[ComicList alloc] init];
        [comic setValuesForKeysWithDictionary:dic];
        [self.juniorArr addObject:comic];
    }
    
    for (NSInteger i = 0; i < _comicsThird.data.count; i++) {
        if (button.tag == i + 1) {
            NSLog(@"%@",[[_comicsThird.data objectAtIndex:i] objectForKey:@"title"]);
            ComicList *comicsTemp = [self.juniorArr objectAtIndex:i];
            DetailViewController *detail = [[DetailViewController alloc] init];
            [self.navigationController pushViewController:detail animated:YES];
            detail.comic = comicsTemp;
            NSLog(@"detail comics %@", detail.comic.commic_id);
            [detail release];
        }
        
    }
}
// 专题1 -> 专题列表1 index 1

- (void)buttonActionFour:(UIButton *)button
{
    for (NSInteger i = 0; i < 4; i++) {
        if (button.tag == i + 1) {
            TopicListViewController *topicVC = [[TopicListViewController alloc] init];
            [self.navigationController pushViewController:topicVC animated:YES];
            [topicVC setTitle:[[self.comicsForth.data objectAtIndex:i] objectForKey:@"topic_title"]];
            topicVC.topic_id = [[self.comicsForth.data objectAtIndex:i] objectForKey:@"topic_id"];
            topicVC.index = @"2";
            [topicVC release];
        }
    }
}
- (void)buttonActionFive:(UIButton *)button
{
    
    for (NSDictionary *dic in self.comicsFive.data) {
        ComicList *comic = [[ComicList alloc] init];
        [comic setValuesForKeysWithDictionary:dic];
        [self.girlArr addObject:comic];
        [comic release];
    }
    for (NSInteger i = 0; i < 12; i++) {
        if (button.tag == i + 1) {
            NSLog(@"%@",[[_comicsFive.data objectAtIndex:i] objectForKey:@"title"]);
            
            DetailViewController *detail = [[DetailViewController alloc] init];
            [self.navigationController pushViewController:detail animated:YES];
            detail.comic = [self.girlArr objectAtIndex:i];
            [detail release];
            
        }
    }
}
// 跳转至 专题列表2 index 3;

- (void)buttonActionSix:(UIButton *)button
{
    
    for (NSInteger i = 0; i < 4; i++) {
        if (button.tag == i + 1) {
            TopicListViewController *topicVC = [[TopicListViewController alloc] init];
            [self.navigationController pushViewController:topicVC animated:YES];
            topicVC.topic_id = [[self.comicsSix.data objectAtIndex:i] objectForKey:@"topic_id"];
            topicVC.title = [[self.comicsSix.data objectAtIndex:i] objectForKey:@"topic_title"];
            topicVC.index = @"3";
            [topicVC release];
        }
        
    }
    
}
// 跳转到漫画列表 NewComicsListVC
- (void)totalButtonAction:(UIButton *)button
{
    NewComicsListViewController *newVC = [[NewComicsListViewController alloc] init];
    [self.navigationController pushViewController:newVC animated:YES];
    ComicList *comics = [self.arrTwo firstObject];
    newVC.comicId = [[comics.data objectAtIndex:1] objectForKey:@"classify_id2"];
    
    
    newVC.title = [[comics.data objectAtIndex:1] objectForKey:@"classify_title2"];
    [newVC release];
}
// 热门漫画按钮跳转 ComicsListVC

- (void)hotListButton:(UIButton *)button
{
    
    ComicsListViewController *comicsVC = [[ComicsListViewController alloc] init];
    [self.navigationController pushViewController:comicsVC animated:YES];
    comicsVC.comic_list_id = self.comics.comic_list_id;
    comicsVC.title = self.comics.comic_list_title;
    [comicsVC release];
}
// 跳转至少女列表漫画页面
- (void)girlButtonListAction:(UIButton *)button
{
    ComicsListViewController *comicsVC = [[ComicsListViewController alloc] init];
    [self.navigationController pushViewController:comicsVC animated:YES];
    comicsVC.comic_list_id = self.comicsFive.comic_list_id;
    //    NSLog(@"%@",self.comicsFive.comic_list_id);
    comicsVC.title = self.comicsFive.comic_list_title;
    [comicsVC release];
}

#pragma mark -
#pragma mark Button actions

- (void)showMenu
{
    if (!_sideMenu) {
        RESideMenuItem *itemWithSubItems0 = [[RESideMenuItem alloc] initWithTitle:@"分类列表" action:^(RESideMenu *menu, RESideMenuItem *item) {
            
        }];
        
        RESideMenuItem *homeItem = [[RESideMenuItem alloc]initWithTitle:@"青春往事" image:[UIImage imageNamed:@"5.gif" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *qingChunVC = [[ClassifyViewController alloc] init];
            qingChunVC.title = item.title;
            qingChunVC.comicId = @"7";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:qingChunVC];
            
            [menu setRootViewController:navigationController];
            
        }];
        
        
        RESideMenuItem *exploreItem = [[RESideMenuItem alloc] initWithTitle:@"玄幻" image:[UIImage imageNamed:@"2.jpg" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *xuanHuanVC = [[ClassifyViewController alloc] init];
            xuanHuanVC.title = item.title;
            xuanHuanVC.comicId = @"13";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:xuanHuanVC];
            
            [menu setRootViewController:navigationController];
            
        }];
        
        RESideMenuItem *activityItem = [[RESideMenuItem alloc] initWithTitle:@"热血" image:[UIImage imageNamed:@"1.jpg" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *reXueVC = [[ClassifyViewController alloc] init];
            reXueVC.title = item.title;
            reXueVC.comicId = @"3";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:reXueVC];
            
            [menu setRootViewController:navigationController];
            
        }];
        //            [menu hide];
        RESideMenuItem *profileItem = [[RESideMenuItem alloc] initWithTitle:@"搞笑" image:[UIImage imageNamed:@"7.png" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *gaoXiaoVC = [[ClassifyViewController alloc] init];
            gaoXiaoVC.title = item.title;
            gaoXiaoVC.comicId = @"1";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:gaoXiaoVC];
            
            [menu setRootViewController:navigationController];
            
        }];
        RESideMenuItem *aroundMeItem = [[RESideMenuItem alloc] initWithTitle:@"恐怖" image:[UIImage imageNamed:@"4.jpg" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *kongBuVC = [[ClassifyViewController alloc] init];
            kongBuVC.title = item.title;
            kongBuVC.comicId = @"2";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:kongBuVC];
            
            [menu setRootViewController:navigationController];
            
        }];
        RESideMenuItem *helpPlus1 = [[RESideMenuItem alloc] initWithTitle:@"热门改编" image:[UIImage imageNamed:@"6.jpg" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *gaiBianVC = [[ClassifyViewController alloc] init];
            gaiBianVC.title = item.title;
            gaiBianVC.comicId = @"14";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:gaiBianVC];
            
            [menu setRootViewController:navigationController];
        }];
        RESideMenuItem *helpPlus2 = [[RESideMenuItem alloc] initWithTitle:@"美少女" image:[UIImage imageNamed:@"3.jpg" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *meiVC = [[ClassifyViewController alloc] init];
            meiVC.title = item.title;
            meiVC.comicId = @"11";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:meiVC];
            
            [menu setRootViewController:navigationController];
        }];
        
        RESideMenuItem *helpCenterItem = [[RESideMenuItem alloc] initWithTitle:@"恋爱" image:[UIImage imageNamed:@"0.jpg" ] highlightedImage:nil action:^(RESideMenu *menu, RESideMenuItem *item) {
            self.hidesBottomBarWhenPushed = NO;
            self.navigationController.navigationBarHidden = NO;
            ClassifyViewController *lianAiVC = [[ClassifyViewController alloc] init];
            lianAiVC.title = item.title;
            lianAiVC.comicId = @"9";
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:lianAiVC];
            
            [menu setRootViewController:navigationController];
        }];
        
        RESideMenuItem *itemWithSubItems = [[RESideMenuItem alloc] initWithTitle:@"返回主页 >>" action:^(RESideMenu *menu, RESideMenuItem *item) {
            RootViewController *rootVC = [[RootViewController alloc] init];
            [menu setRootViewController:rootVC];
        }];
        _sideMenu = [[RESideMenu alloc] initWithItems:@[itemWithSubItems0,homeItem, exploreItem, activityItem, profileItem,aroundMeItem, helpPlus1, helpPlus2, helpCenterItem,itemWithSubItems]];
        _sideMenu.verticalOffset = IS_WIDESCREEN ? 20 : 20;
        _sideMenu.hideStatusBarArea = [AppDelegate OSVersion] < 9;
    }
    
    [_sideMenu show];
}

// 搜索按钮
- (void)barButtonAction1:(UIBarButtonItem *)button
{
    self.hidesBottomBarWhenPushed = YES;
    SearchViewController *searchVC = [[SearchViewController alloc] init];
    [self.navigationController pushViewController:searchVC animated:NO];
    self.hidesBottomBarWhenPushed = NO;
    [searchVC release];
}
- (void)dealloc
{
    [_collectionView release];
    [_sideMenu release];
    [_arr release];
    [_tableView release];
    [_comics release];
    [_comicsThird release];
    [_comicsForth release];
    [_comicsFive release];
    [_comicsSix release];
    [_arrTwo release];
    [_arrThree release];
    [_arrFour release];
    [_juniorArr release];
    [_girlArr release];
    [_topicTwoArr release];
    [_notify release];
    [_mbView release];
    [super dealloc];
    
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
